package cn.itsource.pethome.controller;


import cn.itsource.pethome.domain.Department;
import cn.itsource.pethome.domain.DepartmentDTO;
import cn.itsource.pethome.domain.Employee;
import cn.itsource.pethome.service.DepartmentService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

@RestController
@RequestMapping("dept")
//@RestController = @Controller (将当前类交给spring管理)+ @ResponseBody(禁止页面跳转,将数据转换成json字段)
public class DeptController {
    @Autowired
    DepartmentService departmentService;

    /************************接口四要素模板*****************************
     * 方法: 新增方法
     *
     * 请求方式: post
     * 请求地址: insert
     * 请求参数:{employee}
     * 相应参数: JsonResult
     * @author maizi
     * @date 2023/10/8 16:49
     * @param
     * @return
     *****************************************************************/
    @PostMapping("insert")
    public void insert(@RequestBody Department department){
        departmentService.insert(department);
    }

    @GetMapping("findAll")
    public List<Department> findAll(){
        return  departmentService.findAll();

    }
    @GetMapping("getTree")
    public List<Department> getTree(){
        return  departmentService.getTree();

    }

//    public static void main(String[] args) {
//        List<Department> departments = Arrays.asList(
//                new Department(1L, "研发1部"),
//                new Department(2L, "研发2部"),
//                new Department(3L, "研发3部"),
//                new Department(4L, "研发4部"),
//                new Department(5L, "研发5部")
//        );
//        //map de作用: 1.遍历当前集合  2.收集当前操作的返回值生成新的集合
//        Set<Employee> collect = departments.stream().map(department -> {
//            Employee employee = new Employee();
//            employee.setId(department.getId());
//            employee.setUsername(department.getName());
//            return employee;
//        }).collect(Collectors.toSet());
//
//    }
    /************************接口四要素模板*****************************
     * 方法:
     * 请求方式:post
     * 请求地址:/findPage
     * 请求参数:{page:"",name:"",state:"",parentId}
     * 相应参数: JsonResult
     *****************************************************************/
    @PostMapping("findPage")
    public PageInfo<Department> findPage(@RequestBody DepartmentDTO dto){

        return  departmentService.findPage(dto);

    }

     /************************接口四要素模板*****************************
      * 方法:批量删除的方法
      * 请求方式:post
      * 请求地址:batchDelete
      * 请求参数:list
      * 相应参数: JsonResult
      * @author maizi
      * @date 2023/10/10 9:13
      * @param
      * @return
      *****************************************************************/
    @PostMapping("batchDelete")
    public void batchDelete(@RequestBody List<Long> ids){
        System.out.println("接收当前数据:"+ids);

    }


}
